<?php
/** $Id: menu.php 1534 2008-09-21 11:14:36Z francis $ */

/**
 * Menu helper for the portal MyConservus
 *
 */

class MenuHelper extends AppHelper {
/**
 * name property
 *
 * @var string 'Tree'
 * @access public
 */
    var $name = 'Menu';
/**
 * settings property
 *
 * @var array
 * @access private
 */
    var $__settings = array();
/**
 * typeAttributes property
 *
 * @var array
 * @access private
 */
    var $__typeAttributes = array();
/**
 * typeAttributesNext property
 *
 * @var array
 * @access private
 */
    var $__typeAttributesNext = array();
/**
 * itemAttributes property
 *
 * @var array
 * @access private
 */
    var $__itemAttributes = array();
/**
 * helpers variable
 *
 * @var array
 * @access public
 */
	var $helpers = array ('Html');
	
	function generate($data, $options = array()) {
		$this->__settings = array_merge(array(
					'model' => null,
					'alias' => 'name',
					'type' => 'ul',
					'itemType' => 'li',
					'id' => false,
					'class' => false,
					'element' => false,
					'callback' => false,
					'autoPath' => false,
					'left' => 'lft',
					'right' => 'rght',
					'depth' => 0,
					'firstChild' => true,
					'indent' => null,
					'splitDepth' => false,
					'splitCount' => 3,
					), (array)$settings);
	}

	function renderMainMenu($data) {?>
		<ul class="menu" id="main_menu_list">
		<?php foreach($data as $item) {
			$parentId = (empty($item['MenuItem']['child_id']))?$item['MenuItem']['id']:$item['MenuItem']['child_id'];
		?>
			<li><a href="javascript:loadSubMenu(<?php echo $parentId;?>, '<?php echo $item['MenuItem']['url'];?>');" title="<?php echo $item['MenuItem']['label'];?>"><?php echo $item['MenuItem']['label'];?></a></li>
		<?php } ?>
		</ul>
<?php
	}


	function renderSubMenu($data) {?>
		<ul class="menu" id="left_submenu">
		<?php foreach($data as $item): ?>
			<li><a href="javascript:loadArticle('<?php echo $item['MenuItem']['url'];?>');"><?php echo $item['MenuItem']['label'];?></a></li>
		<?php endforeach;?>
		</ul>
<?php
	}


	function show($data) {
		$ul = '<ul>%s</ul>';
		$item = '<li>%s</li>';

		if (empty($data)) {
			return;
		}
		echo '<ul>';
		foreach($data as $line) {
			echo '<li>';
			echo '<span>' . $line['Menu']['name'] . '</span>';
			if (!empty($line['Children'])) {
				$this->show($line['Children']);
			}
			echo '</li>';
		}
		echo '</ul>';
	}
}
?>